import {
  Controller,
  Get,
  Post,
  Put,
  Delete,
  Body,
  Param,
  Query,
  UseGuards,
  UseInterceptors,
  UploadedFile,
  UploadedFiles,
  Session,
  Req,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiConsumes,
} from '@nestjs/swagger';
import { Request } from 'express';
import { JwtAuthGuard } from '@wwjCommon/security/guards/jwt-auth.guard';
import { RolesGuard } from '@wwjCommon/security/guards/roles.guard';
import { Roles } from '@wwjCommon/security/decorators/roles.decorator';
import { Public } from '@wwjCommon/security/decorators/public.decorator';
import { BusinessException } from '@wwjCommon/exception/business.exception';
// @UploadedFile() - 单文件上传，配合 @UseInterceptors(FileInterceptor('file'))
// @UploadedFiles() - 多文件上传，配合 @UseInterceptors(FilesInterceptor('files'))
// @Session() - 获取会话对象，对应PHP Session::get()
// @Req() - 获取Request对象，对应PHP Request
import { MemberCashOutService } from '../../services/admin/member-cash-out.service';

/**
 * CashOutController
 * 对应 PHP: CashOut Controller
 * 对应 Java: @RestController
 *
 * 支持装饰器：
 * - @UploadedFile() - 单文件上传 (对应PHP Request::file())
 * - @UploadedFiles() - 多文件上传
 * - @Session() - 会话管理 (对应PHP Session::get())
 * - @Req() - 请求对象 (对应PHP Request)
 */
@ApiTags('member')
@Controller('adminapi/member')
export class CashOutController {
  constructor(private readonly memberCashOutService: MemberCashOutService) {}

  /**
   * 提现
   * 路由: GET cash_out
   * PHP路由: Route::get('cash_out', 'member.CashOut/lists')
   */
  @Get('cash_out')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async lists(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: lists

      return await this.memberCashOutService.getPage(data);
    } catch (error) {
      throw new BusinessException('lists操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: GET cash_out/:id
   * PHP路由: Route::get('cash_out/:id', 'member.CashOut/info')
   */
  @Get('cash_out/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async info(@Param('id') id: string): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: info

      return await this.memberCashOutService.getInfo(id);
    } catch (error) {
      throw new BusinessException('info操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: PUT cash_out/audit/:id/:action
   * PHP路由: Route::put('cash_out/audit/:id/:action', 'member.CashOut/audit')
   */
  @Put('cash_out/audit/:id/:action')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async audit(
    @Param('id') id: string,
    @Param('action') action: string,
    @Body() data: AuditDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: audit

      return await this.memberCashOutService.audit(id, action, data);
    } catch (error) {
      throw new BusinessException('audit操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: GET cash_out/transfertype
   * PHP路由: Route::get('cash_out/transfertype', 'member.CashOut/getTransferType')
   */
  @Get('cash_out/transfertype')
  @ApiOperation({ summary: '提现' })
  async getTransferType() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getTransferType
      // 直接返回字典数据
      return TransferDict.getTransferType();
    } catch (error) {
      throw new BusinessException('getTransferType操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: PUT cash_out/transfer/:id
   * PHP路由: Route::put('cash_out/transfer/:id', 'member.CashOut/transfer')
   */
  @Put('cash_out/transfer/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async transfer(
    @Param('id') id: string,
    @Body() data: TransferDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: transfer

      return await this.memberCashOutService.transfer(id, data);
    } catch (error) {
      throw new BusinessException('transfer操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: PUT cash_out/remark/:id
   * PHP路由: Route::put('cash_out/remark/:id', 'member.CashOut/remark')
   */
  @Put('cash_out/remark/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async remark(
    @Param('id') id: string,
    @Body() data: RemarkDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: remark

      return await this.memberCashOutService.remark(id, data);
    } catch (error) {
      throw new BusinessException('remark操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: GET cash_out/status
   * PHP路由: Route::get('cash_out/status', 'member.CashOut/getStatusList')
   */
  @Get('cash_out/status')
  @ApiOperation({ summary: '提现' })
  async getStatusList() {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: getStatusList
      // 直接返回字典数据
      return MemberCashOutDict.getStatus();
    } catch (error) {
      throw new BusinessException('getStatusList操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: GET cash_out/stat
   * PHP路由: Route::get('cash_out/stat', 'member.CashOut/stat')
   */
  @Get('cash_out/stat')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async stat(): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: stat

      return await this.memberCashOutService.stat();
    } catch (error) {
      throw new BusinessException('stat操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: PUT cash_out/check/:id
   * PHP路由: Route::put('cash_out/check/:id', 'member.CashOut/checkTransferStatus')
   */
  @Put('cash_out/check/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async checkTransferStatus(
    @Param('id') id: string,
    @Body() data: CheckTransferStatusDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: checkTransferStatus

      return await this.memberCashOutService.checkTransferStatus(id);
    } catch (error) {
      throw new BusinessException('checkTransferStatus操作失败', error);
    }
  }

  /**
   * 提现
   * 路由: PUT cash_out/cancel/:id
   * PHP路由: Route::put('cash_out/cancel/:id', 'member.CashOut/cancel')
   */
  @Put('cash_out/cancel/:id')
  @UseGuards(JwtAuthGuard, RolesGuard)
  @ApiOperation({ summary: '提现' })
  async cancel(
    @Param('id') id: string,
    @Body() data: CancelDto,
  ): Promise<ApiResponse> {
    try {
      // 基于PHP真实逻辑实现
      // PHP原始方法: cancel

      return await this.memberCashOutService.cancel(id);
    } catch (error) {
      throw new BusinessException('cancel操作失败', error);
    }
  }
}
